<%@ include  file="Header.jsp" %> 
<jsp:directive.page import="java.sql.*"/>
<jsp:directive.page import="Connectivity.ConnectionManager"/>
 <%
int group_id=1;

String item_no = request.getParameter("itemgroup_id")!=null?request.getParameter("itemgroup_id"):"0";
int itemgroup_id=Integer.parseInt(item_no);
%>
   <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
   "http://www.w3.org/TR/html4/loose.dtd">

   <html>

      <head>
         <meta http-equiv="Content-Type" 
            content="text/html; charset=windows-1256">
         <title>   Group Creation  </title>
      </head>
 <SCRIPT language=JavaScript>
	var reset = 0;
	var lastKeyCode = 0;
	var lastKeyCode1 = 0;
    var lastKeyCode2 = 0;
  var comboselec=1;  var comboflag=0;

	


function mySubmit()
{
  var flag=0;			

		  if(document.itemEntry.itemcode.value==0){
					flag=1;
					alert('plz Enter the groupcode');
					document.itemEntry.itemcode.focus();
					return false;
			}
			if(document.itemEntry.itemname.value==0){
					flag=1;
					alert('plz Enter the name');
					document.itemEntry.itemname.focus();
					return false;
			}
			
			   if(flag==0)
			{document.itemEntry.action = "/Genius/ItemEntry";
			document.itemEntry.submit();
		    return true;
		     }
		}		

	function callFun(groupcode, groupname){
		//document.getElementById("del").style.display = 'block';
		document.groupcreation.create.value = "Update";
		document.groupcreation.groupcode.value = groupcode;
		document.groupcreation.groupname.value = groupname;
		//document.groupcreation.reservation.value = res;
		reset=1;
	}

	function  onChange(){
		document.itemEntry.create.value= "create";
		if(reset==1){
		document.getElementById("del").style.display = 'none';
		}
	}
	
	
	function combosel(obj)
	{
	
	
	//comboselec=(document.itemEntry.groupsel.value);
	//alert(""+comboselec);
	if(obj.selectedIndex=='0'){
			alert('Please Select '+obj);
		}
		 if(obj.name=='groupsel')
		 {insertParam("itemgroup_id",(obj.value));}
		 	
	}
	function  callDelete(){
		var flag = 0 ;
		if(isNumeric(document.itemEntry.groupname.value) || isNull(document.itemEntry.groupname.value) || isBlank(document.itemEntry.groupname.value)){
			flag=1;
			alert('plz select the group');
			document.itemEntry.groupname.focus();
			return false;
		}
		
		if(flag==0){		
		if(confirm('You Really want to delete?')){
			document.itemEntry.action = "itemEntry.jsp";
		  	document.itemEntry.submit();
			}else{
				return false;
			}
			
		}
	}

	function setFocusOnLoad(){
		window.document.itemEntry.elements[0].focus();
	}
	
	function startsWithDigit(val)	{
		var counter		= 0;
		var	singleChar	= "";
		var	validChars	= "0123456789";
	
		if(isBlank(val))
			return false;
	
		val = val.substr(0, 1);
	
		if(validChars.indexOf(val) != -1){
			return false;
		}
		return true;
	}
	

	
function insertParam(key, value) 
{    
	key = escape(key); value = escape(value);
    var kvp = document.location.search.substr(1).split('&');
 	if (kvp == '') 
 	{
 	document.location.search = '?' + key + '=' + value;
 	}
 	else 
 	{
 	var i = kvp.length; var x; while (i--) 
 	{
 	  x = kvp[i].split('='); 
 	if (x[0] == key) 
  {
   x[1] = value;
   kvp[i] = x.join('=');
   break;
  }
  }
  if (i < 0) 
  { kvp[kvp.length] = [key, value].join('='); }
        //this will reload the page, it's likely better to store this until finished 
    document.location.search = kvp.join('&');         
  }
} 
	
	function valid()
	{
	  
	
	}
	
	
	/*function  stopSpecialChar(){
		if((window.event.keyCode >= 33  && window.event.keyCode <= 44) || (window.event.keyCode >= 47  && window.event.keyCode <= 48) || (window.event.keyCode >= 57  && window.event.keyCode <= 64) || window.event.keyCode == 96 || (window.event.keyCode >= 91  && window.event.keyCode <= 94) || (window.event.keyCode >= 123  && window.event.keyCode <= 126)){
		window.event.keyCode = 0;
		}
	}*/
	
  </SCRIPT>
      
<body>
 
<form name=itemEntry method=get action="">
    <table align=center border=1 width=50%>
    <tr><td align=center width=100%><font size=4> Item Entry </font> </td></tr>
    <tr><td align=center >SELECT GROUP:&nbsp;&nbsp;&nbsp;
    <select name=groupsel id="groupsel" onchange="combosel(this)">
     
<%
try
{
String groupquerry="select group_id,group_name from item_group_master where status='V'";
  prst1=con.prepareStatement(""+groupquerry);
  ResultSet rs1=prst1.executeQuery();
  {  out.println("<option value='0'>--select--</option> ");  }
  while(rs1.next())
  {

  if (itemgroup_id==(Integer.parseInt(""+rs1.getString(1))))
  { out.println("<option value="+rs1.getString(1)+" selected>"+rs1.getString(2)+"</option>");  }
  else
  {

    { out.println("<option value="+rs1.getString(1)+">"+rs1.getString(2)+"</option>");  }

}
}





 %>

</select>
</td></tr>

<%if(itemgroup_id!=0){ %>

<tr ><td>
<table class="maintable" id="showExisting" align="center"   cellpadding="0" width="693" border=1>
<tr><td colspan=2 align=center><b>Enter the item details</b></td></tr>
			<tr><td colspan=1 align=right>ITEM CODE: &nbsp;&nbsp;</td>		
				<td colspan=1 align=left><input type="text" name="itemcode" value=""/><br></td></tr>		
			<tr><td colspan=1 align=right>ITEM NAME: &nbsp;&nbsp;</td>		
			<td colspan=1 align=left><input type="text" name="itemname" value=""/></td></tr>
			<tr><td colspan=1 align=right>ITEM DESC: &nbsp;&nbsp;</td>		
			<td colspan=1 align=left><input type="text" name="itemdesc" value=""/></td></tr>
			<tr><td colspan=1 align=right>COMPANY NAME: &nbsp;&nbsp;</td>		
			<td colspan=1 align=left><input type="text" name="companyname" value=""/></td></tr>
			<tr><td colspan=1 align=right><input type=submit name=submit value="submit" onclick=mySubmit()> &nbsp;&nbsp;</td>		
			<td colspan=1 align=left><input type=reset name=reset value="reset"  ></td></tr>
</table> 
<%

String groupquerry1="select item_code,item_name from item_master where group_id="+itemgroup_id+" and status='V'";
  PreparedStatement prst11=con.prepareStatement(""+groupquerry1);
  ResultSet rs11=prst11.executeQuery();
  while(rs11.next())
  {

 %>
    <tr>
    <td align=center>
    <a href="javascript:callfun('<%=rs11.getString(1)%>','<%=rs11.getString(2) %>')"><%=rs11.getString(2)%></a> </td></tr>
<%
}
%>


</td></tr>

<%} %>
    </table>     
   </form>    
       
       
       
       
          
      

 
</tr>
</tr></td>   
<%
}
catch(Exception e)
{e.printStackTrace();}

 %></td></tr></table>

      </body>
	
   </html>